package JDBCLEARN;

import com.alibaba.druid.pool.DruidAbstractDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;

public class test {
    public static void main(String[] args) throws Exception {
        //实例化测试
        JdbcLearnBackup jdbcLearnBackup = new JdbcLearnBackup();
        jdbcLearnBackup.deleteDb();


        //德鲁伊连接池测试
        Properties properties = new Properties();
        properties.load(new FileInputStream("src/JDBCLEARN/jdbc.properties"));
        DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
        Connection connection = dataSource.getConnection();
        System.out.println("connection = " + connection);

        String sql = "select * from student";
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery();
        //通过next指向下一行 while循环遍历
        while (resultSet.next()){
            //7.解析结果中数据字段
            System.out.println("resultSet.getInt(\"sid\") = " + resultSet.getInt("sid"));
            System.out.println("resultSet.getString(\"ssex\") = " + resultSet.getString("ssex"));
            System.out.println("resultSet.getInt(\"sage\") = " + resultSet.getString("sage"));
            System.out.println("--------------------------------");

        }


    }
}
